package com.youlu.campus.web.community.controller;

import com.youlu.campus.common.utils.excel.ExcelUtils;
import com.youlu.campus.entity.VO.req.ImportExcelMajorInfoVO;
import com.youlu.campus.entity.VO.req.MajorQueryReq;
import com.youlu.campus.service.university.MajorInfoService;
import com.yuelin.infrastructure.quantum.common.QResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
public class MajorInfoController {


    @Autowired
    private MajorInfoService majorInfoService;

    @PostMapping("/mini-app/major/search")
    public QResult search(@RequestBody MajorQueryReq majorQueryReq){
        return QResult.success(majorInfoService.list(majorQueryReq));
    }

    @PostMapping("/public/major/import")
    public QResult importMajor(@RequestParam("file") MultipartFile file){
        ExcelUtils<ImportExcelMajorInfoVO> excelUtil = new ExcelUtils();
        List<ImportExcelMajorInfoVO> excelDataList = excelUtil.readExcel(file, ImportExcelMajorInfoVO.class);
        majorInfoService.saveBatch(excelDataList);
        return QResult.success(null);
    }
}
